package com.lws.omapicompat.google

import android.os.Build
import android.se.omapi.Session
import androidx.annotation.RequiresApi
import com.lws.omapicompat.ChannelCompat
import com.lws.omapicompat.ReaderCompat
import com.lws.omapicompat.SessionCompat

@RequiresApi(Build.VERSION_CODES.P)
class SessionNew(private val readerNew: ReaderNew, private val session: Session): SessionCompat {

    override fun close() {
        session.close()
    }

    override fun closeChannels() {
        session.closeChannels()
    }

    override fun getATR(): ByteArray? {
        return session.atr
    }

    override fun getReader(): ReaderCompat {
        return readerNew
    }

    override fun isClosed(): Boolean {
        return session.isClosed
    }

    override fun openBasicChannel(aid: ByteArray?, p2: Byte): ChannelCompat? {
        val channel = session.openBasicChannel(aid, p2) ?: return null
        return ChannelNew(this, channel)
    }

    override fun openBasicChannel(aid: ByteArray?): ChannelCompat? {
        return openBasicChannel(aid, 0.toByte())
    }

    override fun openLogicalChannel(aid: ByteArray?, p2: Byte): ChannelCompat? {
        val channel = session.openLogicalChannel(aid, p2) ?: return null
        return ChannelNew(this, channel)
    }

    override fun openLogicalChannel(aid: ByteArray?): ChannelCompat? {
        return openLogicalChannel(aid, 0.toByte())
    }
}